﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace LastfmNet.Models
{
    public abstract class LastfmModelBase
    {
        public abstract void InitializeFromXmlNode(XmlNode node);

        public static IList<T> GetList<T>(XmlNode parentNode, string itemsXmlName = null) where T : LastfmModelBase, new()
        {
            // if (itemsXmlName == null) itemsXmlName = typeof(T).Name.ToLower();
            IList<T> items = new List<T>();
            if (parentNode == null) return items;
            foreach (XmlNode item in parentNode.ChildNodes)
            {
                if (itemsXmlName == null || item.Name == itemsXmlName)
                {
                    T newItem = new T();
                    newItem.InitializeFromXmlNode(item);
                    items.Add(newItem);
                }
            }
            return items;
        }
    }
}
